package me.vudu.Conflict.Runnables;

import me.vudu.Conflict.ConflictPlugin;

import org.getspout.spoutapi.player.SpoutPlayer;

/**
 * heilt Spieler, wenn im Umkreis von x Feldern der Basis
 * @author vwendel
 *
 */
public class PlayerHealerRunnable implements Runnable{
	
	@Override
	public void run() {
		  for(SpoutPlayer p: ConflictPlugin.players){
			  
    		   if(ConflictPlugin.playerIsInTeam(p).equals("red")){ //red
    			   if(ConflictPlugin.defenseTowerRed>0){//nur wenn defenseTower gebaut und nur im Umkreis von x Feldern
    				   if(p.getLocation().distance(p.getWorld().getBlockAt(ConflictPlugin.baseBlocksRed.get(0).getX(), ConflictPlugin.baseBlocksRed.get(0).getY(), ConflictPlugin.baseBlocksRed.get(0).getZ()).getLocation())<ConflictPlugin.isInBaseBuild){
        				   p.setHealth(Math.min(20,p.getHealth()+1));
    				   }
    			   }
    			   
    		   }else{ //Blue
    			   if(ConflictPlugin.defenseTowerBlue>0){
    				   if(p.getLocation().distance(p.getWorld().getBlockAt(ConflictPlugin.baseBlocksBlue.get(0).getX(), ConflictPlugin.baseBlocksBlue.get(0).getY(), ConflictPlugin.baseBlocksBlue.get(0).getZ()).getLocation())<ConflictPlugin.isInBaseBuild){
        				   p.setHealth(Math.min(20,p.getHealth()+1));
    				   }
    			   }
    		   }
	    	   
	       }
	}

}
